package org.mipt.infsec.steganography.impl.petzib.keys;

import org.mipt.infsec.steganography.api.datastorage.keys.Key;
import org.mipt.infsec.steganography.impl.petzib.datastorage.Dictionary;
import org.mipt.infsec.steganography.impl.petzib.datastorage.String;

public class KeyImpl extends Key<Integer>
{
    @Override
    public Object hideKey()
    {
        try{
            return Dictionary.getInstance().getString(getValue());
        } catch(Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public void seekKey(Object data) throws ClassCastException
    {
        if (!(data instanceof String))
            throw new ClassCastException("Incompatible type of key source");

        setValue(((String) data).hashCode());
    }

    public static java.lang.String[] hideKeys(KeyImpl[] keys)
    {
        java.lang.String[] result = new java.lang.String[keys.length];
        for (int i = 0; i < keys.length; i++)
        {
            result[i] = (java.lang.String)keys[i].hideKey();
        }
        return result;
    }

}
